package com.edu.exam.entity.quality.workflow;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 审核流程定义实体类
 * [所属模块] E-05 巡考管理模块
 * 对应数据库表：audit_flow_definition
 *
 * 根据E-05巡考管理模块设计文档实现
 * 管理审核流程的定义信息，支持人工审核和跳过审核两种流程类型。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "audit_flow_definition")
@Comment("审核流程定义表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditFlowDefinition {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 审核流程唯一标识符
     */
    @NotBlank(message = "审核流程ID不能为空")
    @Size(max = 50, message = "审核流程ID长度不能超过50个字符")
    @Column(name = "flow_id", nullable = false, length = 50, unique = true)
    private String flowId;

    /**
     * 审核流程代码
     */
    @NotBlank(message = "审核流程代码不能为空")
    @Size(max = 32, message = "审核流程代码长度不能超过32个字符")
    @Column(name = "flow_code", nullable = false, length = 32, unique = true)
    private String flowCode;

    /**
     * 审核流程名称
     */
    @NotBlank(message = "审核流程名称不能为空")
    @Size(max = 200, message = "审核流程名称长度不能超过200个字符")
    @Column(name = "flow_name", nullable = false, length = 200)
    private String flowName;

    /**
     * 审核流程描述
     */
    @Column(name = "flow_description", columnDefinition = "TEXT")
    private String flowDescription;

    /**
     * 审核流程类型（1-人工审核，2-跳过审核）
     */
    @NotNull(message = "审核流程类型不能为空")
    @Column(name = "flow_type", nullable = false)
    private Integer flowType;

    /**
     * 审核流程状态（DRAFT-草稿，ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃）
     */
    @NotBlank(message = "审核流程状态不能为空")
    @Size(max = 20, message = "审核流程状态长度不能超过20个字符")
    @Column(name = "flow_status", nullable = false, length = 20)
    private String flowStatus;

    /**
     * 版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version", nullable = false)
    private Integer version;

    /**
     * 是否为默认流程
     */
    @NotNull(message = "默认流程标识不能为空")
    @Column(name = "is_default", nullable = false)
    private Boolean isDefault;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 流程优先级（1-最高，依次递减）
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 适用题型（JSON格式，存储题型代码列表）
     */
    @Column(name = "applicable_question_types", columnDefinition = "TEXT")
    private String applicableQuestionTypes;

    /**
     * 适用难度级别（JSON格式，存储难度级别列表）
     */
    @Column(name = "applicable_difficulty_levels", columnDefinition = "TEXT")
    private String applicableDifficultyLevels;

    /**
     * 适用科目（JSON格式，存储科目ID列表）
     */
    @Column(name = "applicable_subjects", columnDefinition = "TEXT")
    private String applicableSubjects;

    /**
     * 流程配置（JSON格式，存储流程的详细配置信息）
     */
    @Column(name = "flow_configuration", columnDefinition = "TEXT")
    private String flowConfiguration;

    /**
     * 审核环节配置（JSON格式，存储环节的配置信息）
     */
    @Column(name = "step_configuration", columnDefinition = "TEXT")
    private String stepConfiguration;

    /**
     * 审核规则配置（JSON格式，存储规则的配置信息）
     */
    @Column(name = "rule_configuration", columnDefinition = "TEXT")
    private String ruleConfiguration;

    /**
     * 通知配置（JSON格式，存储通知的配置信息）
     */
    @Column(name = "notification_configuration", columnDefinition = "TEXT")
    private String notificationConfiguration;

    /**
     * 超时配置（JSON格式，存储超时的配置信息）
     */
    @Column(name = "timeout_configuration", columnDefinition = "TEXT")
    private String timeoutConfiguration;

    /**
     * 审核人员配置（JSON格式，存储审核人员的配置信息）
     */
    @Column(name = "auditor_configuration", columnDefinition = "TEXT")
    private String auditorConfiguration;

    /**
     * 流程标签（JSON格式，存储流程的标签信息）
     */
    @Column(name = "flow_tags", columnDefinition = "TEXT")
    private String flowTags;

    /**
     * 流程元数据（JSON格式，存储流程的扩展元数据）
     */
    @Column(name = "flow_metadata", columnDefinition = "TEXT")
    private String flowMetadata;

    /**
     * 生效时间
     */
    @Column(name = "effective_time")
    private LocalDateTime effectiveTime;

    /**
     * 失效时间
     */
    @Column(name = "expiry_time")
    private LocalDateTime expiryTime;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 审核者ID
     */
    @Size(max = 50, message = "审核者ID长度不能超过50个字符")
    @Column(name = "reviewed_by", length = 50)
    private String reviewedBy;

    /**
     * 发布者ID
     */
    @Size(max = 50, message = "发布者ID长度不能超过50个字符")
    @Column(name = "published_by", length = 50)
    private String publishedBy;

}